import hashlib
import random
import string

stringLength = 32


def random_string():
    """Generate a random string of fixed length """
    letters = string.ascii_lowercase
    return ''.join(random.choice(letters) for i in range(stringLength))


if __name__ == '__main__':
    num_train = 10000
    num_valid = 100
    num_total = num_train + num_valid

    samples = dict()

    while True:
        message = random_string()
        m = hashlib.sha256()
        m.update(bytes(message, encoding='ascii'))
        hash = m.hexdigest()
        samples[message] = hash
        if len(samples) == num_total:
            break

    samples = list(samples.items())

    train = ['{} {}\n'.format(sample[0], sample[1]) for sample in samples[:num_train]]
    valid = ['{} {}\n'.format(sample[0], sample[1]) for sample in samples[num_train:]]

    with open('train.txt', 'w') as file:
        file.writelines(train)

    with open('valid.txt', 'w') as file:
        file.writelines(valid)
